<extend name="Layout/ins_page" />
<block name="content">
<link href="/sap/demo.css" rel="stylesheet" type="text/css" />
<script src="/sap/scripts/boot.js" type="text/javascript"></script>
<style>
.mini-grid-row{height: 30px}
table img{width: 40px}
</style>


<body style="">
<div class='show-pic'><img /></div>
			<input type="input" class='mini-textbox' id='pid'style="width: 180px;display: none" value="{$id}" /> <span class='span'>
			 
		      &nbsp;&nbsp;选择清单:<input id="combo1" onValuechanged="change()" class="mini-combobox" style="width: 320px;" textField="name" valueField="id" emptyText="请选择清单..." url="/Shelves/getMylist" value="" allowInput="true" showNullItem="true" nullItemText="请选择清单..." />
				<a class="mini-button" iconCls="icon-downgrade" onclick="send()">通知上架</a>
				<br/>
				<br/>
				<div id="grid2" class="mini-datagrid" style="width: 100%; height: 500px;"  allowCellEdit="true" 	idField="id" multiSelect="true" showPager="false" allowCellEdit="true" allowCellSelect="true"
				onCellendedit='cellendedit'
				>
				 <div property="columns">
					    <div header="日期" field="ctime"  ></div>
					 	<div header="OA物料编号" field="oa_id" ></div>
				        <div header="物料编号" field="code" ></div>
				        <div header="物料名称" field="name" ></div>
				        <div header="颜色" field="color" ><input property="readonly" class="mini-textbox" style="width:100%;"/></div>
				        <!--<div header="图片" field="img" ></div>-->
				        <!--<div header="订货说明" field="caption" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>-->
				        <!--<div header="毛利" field="maoli" ></div>-->
				        <!--<div header="商城价" field="mall_price" > <input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="市场价" field="market_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="毛利率" field="maolilv" ></div>-->
				        <!--<div header="采购价" field="purchase_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="实际采购价" field="r_purchase_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="分期数" field="by_stages" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="费率（%）" field="by_stages_rate" ><input property="editor" class="mini-spinner" minValue="0" maxValue="100" /></div>-->
				        <!--<div header="预估运费" field="freight" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="赠品价格" field="gift_price" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="银行佣金" field="bank_commission" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="增值税等17%" field="zzs" ></div>-->
				        <!--<div header="包装费" field="packing_charge" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="返利金额" field="rebate" ><input property="editor" class="mini-spinner" minValue="0" maxValue="99999999" /></div>-->
				        <!--<div header="天猫" field="tamll" ></div>-->
				        <!--<div header="天猫销售数量" field="tamll_sale" ></div>-->
				        <!--<div header="京东" field="jd" ></div>-->
				        <!--<div header="京东销售数量" field="jd_sale" ></div>-->
				        <!--<div header="广发" field="guangfa" ></div>-->
				        <!--<div header="建行" field="jianhang" ></div>-->
				        <!--<div header="招行" field="zhaohang" ></div>-->
				        <!--<div header="交行" field="jiaohang" ></div>-->
				        <!--<div header="民生" field="minsheng" ></div>-->
				        <!--<div header="平安" field="pingan" ></div>-->
				        <!--<div header="中信" field="zhongxin" ></div>-->
				        <!--<div header="产品毛重(kg)" field="weight" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>-->
				        <!--<div header="外包装尺寸" field="packing_size" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>-->
					    <!--<div header="推荐理由" field="recommended_reason" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>-->
					     <!--<div header="赠品说明" field="gift_note" ><input property="editor" class="mini-textbox" style="width:100%;"/></div>-->
					
					 
					  
				</div>
			  </div>
				




	<script type="text/javascript">
		mini.parse();
		
	
		var pid = mini.get('pid').getValue();
		mini.get('combo1').setValue(pid);
		change();
		function onFilterChanged(e) {
			var namebox = mini.get("name");
			var codebox = mini.get("code");
			var name = namebox.getValue().toLowerCase();
			var code = codebox.getValue().toLowerCase();
			//多条件组合过滤
			grid1.filter(function(row) {

				//name
				var r1 = true;
				if (namebox) {
					r1 = String(row.name).toLowerCase().indexOf(name) != -1;
				}

				var r2 = true;
				if (code) {
					r2 = String(row.code).toLowerCase().indexOf(code) != -1;
				}

				return r1 && r2;
			});
		}

		var grid2 = mini.get("grid2");
		
		
		 grid2.on("drawcell", function (e) {
	            var record = e.record,
	                column = e.column,
	                field = e.field,
	                value = e.value;
	            	if (field == "maoli") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		 e.cellHtml=(fmt(record.mall_price)-fmt(record.purchase_price)+fmt(record.rebate)-fmt(record.freight)-fmt(record.gift_price)-fmt(record.bank_commission)-zzs).toFixed(2);
	          		  }
	            	
	            	if (field == "maolilv") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		 var  maoli =(fmt(record.mall_price)-fmt(record.purchase_price)+fmt(record.rebate)-fmt(record.freight)-fmt(record.gift_price)-fmt(record.bank_commission)-zzs);
	            	
	            		e.cellHtml= (maoli/fmt(record.mall_price)*100).toFixed(2);
	            		
	          		  }
	            	
	            	if (field == "zzs") {
	            		 var zzs = (fmt(record.mall_price)-fmt(record.purchase_price))*0.07; //增值
	            		e.cellHtml= (zzs).toFixed(2);
	            		
	          		  }
	            	
	            	if (field == "img") {
	            		
	            		 e.cellHtml="<img src='"+record.img+"' class='item-img'>";
	          		  }

             if (field == "oa_id") {
                 e.cellHtml = '<a href="/SapSupplier/itemshow/id/'+value+'" target=_blank>'+value+'</a>&nbsp; ';
             }

	            });
		
		 function fmt(num){
			 return parseFloat(num);
		 }
		 
		function cellendedit(e){
			 column = e.column,
		        field = e.field,
		        value = e.value;
				if(e.record._state!=null)
				update(mini.encode(e.record));
		}
		
		
		
		function update(data){
			
			$.ajax({
				url : "/Shelves/upadteDetailed",
				type : "post",
				data : {
					data : data
				},
				dataType : 'json',
				success : function(data) {
					change();
				}
			});
		}
	

		function search() {
			var key = mini.get('key').getValue();
			grid1.load({
				'key' : key
			});
		}
		function adds() {

			var id = mini.get('combo1').getValue();
			if (id == '') {
				mini.alert('请选择清单');
				return;
			}
			var data = new Object();
			var items = grid1.getSelecteds();
			grid1.removeRows(items);
			var selecteds = grid2.getData();
			var check = true;
			var dataIndex = 0;
			for (var index = 0; index < items.length; index++) {
				for (var sindex = 0; sindex < selecteds.length; sindex++) {
					if (items[index].code == selecteds[sindex].code) {
						check = false;
					}
				}
				if (check) {
					grid2.addRow(items[index]);
					data[dataIndex] = items[index];
					dataIndex++;
				} else {
					check = true;
				}
			}
			if (data.length == 0)
				return;
			var postData = mini.encode(data);
			$.ajax({
				url : "/Shelves/saveShelvesDetailed",
				type : "post",
				data : {
					data : postData,
					pid : id
				},
				dataType : 'json',
				success : function(data) {
					change();
				}
			});

		}
		function addAll() {
			var items = grid1.getData();
			grid1.removeRows(items);
			grid2.addRows(items);
		}

		function removes() {
			var items = grid2.getSelecteds();
			var ids = '';
			for (var index = 0; index < items.length; index++) {
				ids += items[index].id + ",";
			}

			$.ajax({
				url : "/Shelves/delShelvesDetailed",
				type : "post",
				data : {
					ids : ids
				},
				dataType : 'json',
				success : function(data) {
				}
			});
			grid2.removeRows(items);
			//  grid1.addRows(items);
		}

		function change() {

			var id = mini.get('combo1').getValue();
			if (id == '') {

				return;
			}
			loadingmsg('加载清单明细..')

			$.ajax({
				url : "/Shelves/getShelvesDetailed",
				type : "post",
				data : {
					pid : id
				},
				dataType : 'json',
				success : function(data) {
					colseloading();
					grid2.setData(data);
					$('#qdan-show').show();
				}
			});

		}

		function promptClick() {

			mini.prompt("请输入清单名称：", "请输入", function(action, value) {
				if (action == "ok") {
					if (value == '') {
						mini.alert('名称不能为空');
						return;
					}
					saveshelvesList(value);
				}

			});
		}

		function saveshelvesList(name) {

			$.ajax({
				url : "/Shelves/saveshelvesList",
				type : "post",
				data : {
					name : name
				},
				dataType : 'json',
				success : function(data) {
					if (data.code != 0) {
						mini.alert('添加成功');
						mini.get('combo1').setData(data.data);
						mini.get('combo1').setValue(data.code);
					}

				}
			});

		}

		function onButtonEdit(e) {
			var btnEdit = this;
			var id = mini.get('combo1').getValue();
			if (id == '') {
				mini.alert('请选择清单');
				return;
			}
			if (grid2.getData().length == 0) {
				mini.alert('清单物料数据为空');
				return;
			}
			mini.open({
				url : "/Shelves/select",
				title : "选择平台",
				width : 650,
				height : 380,
				ondestroy : function(action) {

					if (action == "ok") {
						var iframe = this.getIFrameEl();
						var data = iframe.contentWindow.GetData();
						data = mini.clone(data);
						data.listId = mini.get('combo1').getValue();
						send(data);

					}
				}
			});

		}
		  jQuery('.item-img').live('click',function(){
	        	window.open(jQuery(this).attr('src'));
	        })
		 
        function send(){
        	var id = mini.get('combo1').getValue();
        	if(id==''){
        	mini.alert('请选择清单');
        	return;
        	}
        	loadingmsg('发送中....');
            $.ajax({
                url: "/Shelves/sendnotice",
                type: "post",
                data: { id:id },
                dataType:'json',
                success: function (data) {
                	  mini.unmask(document.body);
                   	  mini.alert(data.msg)
               	
                   
                }
            });
        }
		  
		  
		  jQuery('table img').live('hover',function(event){
			  
			  if(event.type=='mouseenter'){ 
				  jQuery(".show-pic img").attr('src',jQuery(this).attr('src'))
				  jQuery('.show-pic').css({'left':event.pageX+'px','top':'30%'})
				  jQuery(".show-pic").fadeIn(500);
				  }else{ 
						jQuery(".show-pic").hide();
				  }
			}
		  )

	</script>
	
</body>
</block>
<block name="js"> <script type="text/javascript">
	function save() {
		if ($("input:checked[name='user_id[]']").length < 1) {
			ui_error("请选择用户");
			return false;
		}
		;

		var vars = $("#form_data").serialize();
		sendAjax("{:U('save_user')}", vars, function(data) {
			if (data.status) {
				ui_alert(data.info, function() {
					parent.location.reload(true);
					myclose();
				});
			}
		});

	}
</script> </block>